package entity.user;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import entity.file.FileName;
import entity.role.UserRole;

@SuppressWarnings("serial")
@Entity
@Table(name = "USER")
public class User implements Serializable {
	private String id;
	private String account;
	private String password = "111111";
	private String name;
	private String phone;
	private Boolean state = true;// 状态（控制账号是否可以登录true:可以登录，false:不可以）
	private Boolean canDelete = true;// 该账号是否可以被删除（true:可以，false,不可以）
	private List<UserRole> userRoles = new ArrayList<>(0);
	private FileName attachment;// 用户附件（测试文件上传）

	public User() {
		// System.out.println("---create User---");
	}

	public User(String account, String password, String name, String phone) {
		super();
		this.account = account;
		this.password = password;
		this.name = name;
		this.phone = phone;
	}

	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "PHONE", length = 11)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "NAME", length = 20)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "PASSWORD", length = 32)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "ACCOUNT", length = 16)
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "file_name_fk")
	public FileName getAttachment() {
		return attachment;
	}

	public void setAttachment(FileName attachment) {
		this.attachment = attachment;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	public List<UserRole> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(List<UserRole> userRoles) {
		this.userRoles = userRoles;
	}
	@Column(name = "state")
	public Boolean getState() {
		return state;
	}

	public void setState(Boolean state) {
		this.state = state;
	}
	@Column(name = "candelete")
	public Boolean getCanDelete() {
		return canDelete;
	}

	public void setCanDelete(Boolean canDelete) {
		this.canDelete = canDelete;
	}
	
	
}
